var app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    inquiry:"",
    sickrela: [{
        relation: '家庭成员',
        index: 1
      },
      {
        relation: '亲戚',
        index: 2
      },
      {
        relation: '朋友',
        index: 3
      },
      {
        relation: '其他',
        index: 4
      }
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var bgc = wx.getStorageSync('color')
    if (options.keywords) {
      var zid = options.zid
      var name = options.name
      var keywords = options.keywords
      that.setData({
        keywords: options.keywords,
        name: name,
        keywords: keywords,
        zid: zid
      })
    }
    if (options.myinfo) {
      var myinfo = options.myinfo
      that.setData({
        myinfo: myinfo
      })
    }
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    console.log(options.inquiry)
    that.setData({
      bgc: bgc,
      inquiry: options.inquiry
    })
    that.getMyown()
    that.getMyalluser()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  next(){
    if (this.data.inquiry != 4){
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/huanzhezhifu/huanzhezhifu?inquiry=' + this.data.inquiry,
      })
    }else{
      wx.navigateTo({
        url: '/hyb_yl/backstageServices/pages/seldrup/seldrup?inquiry=' + this.data.inquiry,
      })
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getMyown()
    this.getMyalluser()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  addPeo(e) {
    var sickrela = JSON.stringify(this.data.sickrela)
    var sick_index = e.currentTarget.dataset.sick_index
    wx.navigateTo({
      url: "/hyb_yl/userCommunicate/pages/preindex/sickinfo/index?sickrela=" + sickrela + '&sick_index=' + sick_index
    })
  },
  getMyown() {
    var that = this
    var userInfo = wx.getStorageSync('userInfo')
    var openid = wx.getStorageSync('openid')
    var names = userInfo.u_name
    app.util.request({
      'url': 'entry/wxapp/User.myinformation',
      data: {
        names: names,
        openid: openid
      },
      success: function (res) {
        console.log(res)
        that.setData({
          use_own: res.data
        })
      }
    })
  },
  getMyalluser() {
    var that = this
    //检查是否存在一条自己的信息
    app.util.request({
      'url': 'entry/wxapp/User.alluserfamily',
      data: {
        openid: wx.getStorageSync("openid")
      },
      success: function (res) {
        console.log(res)
        that.setData({
          archivesArr: res.data
        })
      },
      fail: function (err) {
        console.log(err)
      },
    })
  },
  choosepeo(e) {
    var that = this
    console.log(e)
    var sick_index = e.currentTarget.dataset.sick_index
    var zid = that.data.zid
    var name = that.data.name
    var keywords = that.data.keywords
    var numcard = e.currentTarget.dataset.numcard
    var sex = e.currentTarget.dataset.sex
    var names = e.currentTarget.dataset.names,
      j_id = e.currentTarget.dataset.j_id,
      tel = e.currentTarget.dataset.tel,
      region = e.currentTarget.dataset.region;
    if (that.data.keywords == 'dianhuawenzhen') {
      wx.navigateTo({
        url: '/hyb_yl/czhuanjiasubpages/pages/questions/index?zid=' + zid + '&name=' + name + '&keywords=' + keywords + '&j_id=' + j_id + '&tel=' + tel
      })
    } else if (that.data.keywords == 'tijianjiedu') {
      wx.navigateTo({
        url: '/hyb_yl/czhuanjiasubpages/pages/healreport/index?zid=' + zid + '&name=' + name + '&keywords=' + keywords + '&j_id=' + j_id + '&tel=' + tel
      })
    } else if (that.data.myinfo == 'open') {
      wx.navigateTo({
        url: '/hyb_yl/userCommunicate/pages/preindex/sickinfo/index?j_id=' + j_id+'&sick_index='+sick_index
      })
    } else {
      var pages = getCurrentPages();
      var prevPage = pages[pages.length - 2];
      prevPage.setData({
        names: names,
        tel: tel,
        region: JSON.parse(region),
        state: 1,
        j_id: j_id,
        numcard: numcard,
        sex: sex
      })
      wx.navigateBack({
        detail: 1
      })
    }

  }
})